﻿using DSTMEETING.Data;
using DSTMEETING.Web.Api.Contracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;

namespace DSTMEETING.Web.Api
{
    /// <summary>
    /// 签名控制器
    /// </summary>
    public class SignatureController : ApiController
    {
        [HttpPost]
        public ApiResult Upload()
        {
            HttpPostedFile file = HttpContext.Current.Request.Files[0];
            string directory = HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["DST.Storage.Signature"]);
            string filepath = string.Format("{0}{1}.{2}", directory, Guid.NewGuid().ToString("N"), GetExtension(file.FileName));
            if (!System.IO.Directory.Exists(directory))
            {
                System.IO.Directory.CreateDirectory(directory);
            }
            file.SaveAs(filepath);

            return new ApiResult();
        }

        private string GetExtension(string filename)
        {
            return filename.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
        }
    }
}
